﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using DTO;

namespace DAO
{
    public class Sim_LoaiSimDAO
    {
       

        public static bool ThemSim_LoaiSim(Sim_LoaiSimDTO sim_loaisimDTO)
        {
            List<SqlParameter> sqlParamas = new List<SqlParameter>();
            sqlParamas.Add(new SqlParameter("@MaSanPham", sim_loaisimDTO.MaSanPham));
            sqlParamas.Add(new SqlParameter("@MaLoaiSim", sim_loaisimDTO.MaLoaiSim));
            return DataProvider.ExecuteNoneQuery("usp_ThemSim_LoaiSim", sqlParamas);
        }

        public static bool XoaSim_LoaiSim(Sim_LoaiSimDTO sim_loaisimDTO)
        {
            List<SqlParameter> sqlParamas = new List<SqlParameter>();
            sqlParamas.Add(new SqlParameter("@MaSanPham", sim_loaisimDTO.MaSanPham));
            sqlParamas.Add(new SqlParameter("@MaLoaiSim", sim_loaisimDTO.MaLoaiSim));
            return DataProvider.ExecuteNoneQuery("usp_XoaSim_LoaiSim", sqlParamas);
        }

        public static List<LoaiSimDTO> DanhSachSim_LoaiSim(int maSanPham)
        {
            List<SqlParameter> sqlParamas = new List<SqlParameter>();
            sqlParamas.Add(new SqlParameter("@MaSanPham", maSanPham));
            DataTable dataTable = DataProvider.ExecuteReader("usp_DanhSachSim_LoaiSim",sqlParamas);
            List<LoaiSimDTO> listLoaiSimDTO = new List<LoaiSimDTO>();
            if (dataTable.Rows.Count > 0)
            {
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    LoaiSimDTO loaiSimDTO = new LoaiSimDTO();
                    loaiSimDTO.MaLoaiSim = int.Parse(dataRow["MaLoaiSim"].ToString());
                    loaiSimDTO.TenLoaiSim = dataRow["TenLoaiSim"].ToString();
                    listLoaiSimDTO.Add(loaiSimDTO);
                }
            }
            else
            {
                listLoaiSimDTO = null;
            }
            return listLoaiSimDTO;
        }
    }
}
